package com.car.advertising.view.viewAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.car.advertising.R;
import com.support.widget.interfacelistener.OnRecyclerViewItemClickListener;
import com.support.widget.interfacelistener.OnRecyclerViewItemLongClickListener;
import com.support.widget.layout.adapter.BaseRecyclerViewAdapter;
import com.support.widget.layout.holder.BaseViewHolder;

import java.util.List;

/**
 * 开发者：LuoYi
 * Time: 2017 14:43 2017/5/4 05
 */

public class BottomMenuAdapter extends BaseRecyclerViewAdapter<String, BaseViewHolder> {

    public BottomMenuAdapter(Context context, List<String> strings) {
        super(context, strings);
    }

    @Override
    protected void bindView(BaseViewHolder holder, int position, String model) {
        BottomMenuHolder menuHolder = (BottomMenuHolder) holder;
        menuHolder.abbreviationTv.setText(model);
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_bottom_menu, parent, false);
        return new BottomMenuHolder(mContext, view, this, getClickListener(), getLongClickListener());
    }

    class BottomMenuHolder extends BaseViewHolder implements OnRecyclerViewItemClickListener, OnRecyclerViewItemLongClickListener {

        public OnRecyclerViewItemClickListener mListener;
        public OnRecyclerViewItemLongClickListener mLongClickListener;
        public TextView abbreviationTv;

        public BottomMenuHolder(Context context, View rootView, RecyclerView.Adapter adapter, OnRecyclerViewItemClickListener clickListener, OnRecyclerViewItemLongClickListener longClickListener) {
            super(context, rootView, adapter, clickListener, longClickListener);
            abbreviationTv = (TextView) rootView.findViewById(R.id.bottom_abbreviation_tv);
            this.mListener = clickListener;
            this.mLongClickListener = longClickListener;
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }

        @Override
        public void onItemClick(ViewGroup parent, View view, int position) {
            if (mListener != null) {
                mListener.onItemClick(parent, view, position);
            }
        }

        @Override
        public void onItemLongClick(ViewGroup parent, View view, int position) {
            if (mLongClickListener != null) {
                mLongClickListener.onItemLongClick(parent, view, position);
            }
        }
    }
}
